<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-09 20:39:23
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-14 23:04:27
 * ------------------------------------------------ *
 * 角色管理 *
 * ------------------------------------------------ */
 namespace Admin\Controller;

class RolesController extends CommonController {
	public function index(){
		if(IS_AJAX){
			switch(I('ajax')){
				case "checkRole":
					$role=D('roles')->where('roleName="'.I('roleName').'"')->find();
					$this->ajaxReturn(!$role);
					break;
				case "addRoles":
					$r = D('roles')->addRoles();
					if($r){
						$this->success('角色添加成功！','',true);	
					}
					$this->error('角色添加失败！','',true);
					break;
				case "editRoles":
					$r = D('roles')->editRoles();
					if($r){
						$this->success('角色修改成功！','',true);	
					}
					$this->error('角色修改失败！','',true);
					break;
				case "delRoles":
					$status = D('roles')->delRoles();
					$this->ajaxReturn($status);
					break;
				default:
					$auths = D('roles')->getRoles();
					$output['data']=$auths;
					$this->ajaxReturn($output);
			}
		}

		$auths = M('auths')->order('concat(authPath,authId)')->where('authFlag!=-1')->select();
		$this->assign('auths',$auths);
		$this->display();
	}

}